<template>
  <view class="city-com-page">
    <uni-data-picker
      v-if="state.pcCode"
      class="data-picker"
      :localdata="state.pcCode"
      popup-title="请选择"
      @change="onchange"
    >
    </uni-data-picker>
  </view>
</template>
<script setup lang="ts">
/**
 * 模块引入
 */
import { reactive, getCurrentInstance, onMounted } from "vue";
const { proxy } = getCurrentInstance();
import pcCode from "./pc-code.json";
/**
 * 接口
 */
/**
 * 父组件数据
 */
const props = defineProps({
  cityName: {
    type: String,
    default: "",
  },
});
/**
 * 数据
 */
const state = reactive({
  pcCode: pcCode,
  hopeCityList: uni.getStorageSync("hopeCityList"),
});
/**
 * 初始方法
 */
onMounted(() => {});
/**
 * 功能方法
 */

const getCity = (data: any) => {
  data.forEach((ele: any) => {
    ele.text = ele.label;
    delete ele.label;
    if (ele.children) {
      getCity(ele.children);
    }
  });
};
const handleCity = (data: any, times: number) => {
  data.map((ele: any) => {
    if (ele.value == state.hopeCityList[times]) {
      emit("update:cityName", ele.text);
      if (ele.children) {
        handleCity(ele.children, times + 1);
      }
    }
  });
};
const onchange = (e: any) => {
  let value: any = [];
  e.detail.value.map((ele: any) => {
    value.push(ele.value);
    emit("update:cityName", ele.text);
  });
  emit("chCity");
  uni.setStorageSync("hopeCityList", value);
};
/**
 * 父组件方法
 * const emit = defineEmits(['function']);
 * emit('function', data);
 */
const emit = defineEmits(["update"]);
/**
 * 父组件传递生命周期方法
 * onShareAppMessage  分享好友
 * onShareTimeline 分享朋友圈
 * onReachBottom 页面内触底
 */
</script>
<script lang="ts">
export default {
  data() {
    return {};
  },
  // #ifdef MP-WEIXIN
  options: { styleIsolation: "shared" },
  // #endif
};
</script>
<style lang="scss" scoped>
@import url("@/static/css/theme.scss");
.data-picker {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  :deep(.uni-data-tree-input) {
    width: 100%;
    height: 100%;
    opacity: 0;
  }
}
</style>
